package cn.sc.allinpay.allfavour.business.setmanage;

import android.content.DialogInterface;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;

import cn.pai.common.listener.OnPromptListener;
import cn.pai.mvp.callback.MpCallBack;
import cn.pai.mvp.presenter.PaiPresenter;
import cn.sc.allinpay.allfavour.app.Constant;
import cn.sc.allinpay.allfavour.business.common.data.CashierData;
import cn.sc.allinpay.allfavour.business.common.utils.SpUtils;

/**
 * 管理员密码修改 presenter
 * author：pany
 * on 2017/12/1 11:27
 */
public class SetManagePresenter extends PaiPresenter<SetManageContract.View> implements SetManageContract.Presenter {

    private SetManageModel model = new SetManageModel();
    private String orgMagPwd;//原管理员密码

    @Override
    public void start() {
        orgMagPwd = SpUtils.get(view.getContext(),Constant.SPNAME, Constant.SpKey.MANAGER_PWD_VOID, Constant.MANAGER_PWD_VOID_DEFAULT);
        if(TextUtils.isEmpty(orgMagPwd)) {
            orgMagPwd = Constant.MANAGER_PWD_VOID_DEFAULT;
        }
        CashierData cashierData = model.getGlobal().getCashierData();
        view.showName("  " + cashierData.getCashierNo() + "  " + cashierData.getCashierName());
    }

    @Override
    public void reqLoginPwdModify() {
        String oriPwd = view.getOriPwd().trim();
        String newPwd = view.getNewPwd().trim();
        String cfmPwd = view.getCfmPwd().trim();
        if(!oriPwd.equals(orgMagPwd)) {
            view.prompt("原管理员密码错误");
            return;
        }
        if(oriPwd.equals(newPwd)) {
            view.prompt("新旧密码不能相同");
            return;
        }
        if(newPwd.length() < 6) {
            view.prompt("新密码长度错误");
            return;
        }
        if (!newPwd.equals(cfmPwd)) {
            view.prompt("新密码与确认密码不一致");
            return;
        }
        SpUtils.put(view.getContext(),Constant.SPNAME, Constant.SpKey.MANAGER_PWD_VOID, cfmPwd);
        view.toast("管理员密码修改成功");
        view.finish();
    }
}
